import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 到店自取
///
class StoreInvite extends StatefulWidget {
  const StoreInvite({Key? key}) : super(key: key);

  @override
  State<StoreInvite> createState() => _StoreInviteState();
}

class _StoreInviteState extends State<StoreInvite> {
  bool service = true;

  bool special = false;

  bool agree = true;

  double get leftWidth {
    return Sizes.default90;
  }

  double get rowHeight {
    return Sizes.default60;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('到店自取'),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('抽成比例',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              padding: const EdgeInsets.all(Sizes.default15),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: ListBody(
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(bottom: Sizes.default10),
                    child: Text(
                      '抽成比例：3% 每单',
                      style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                    ),
                  ),
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      '到店自取订单按此比例抽成',
                      style: StylesUtils.customTextStyle(
                          fontSize: Sizes.default12, color: ColorsUtils.color999),
                    ),
                  )
                ],
              ),
            ),
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('基本设置',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              padding:
                  const EdgeInsets.symmetric(vertical: Sizes.default8, horizontal: Sizes.default15),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: ListBody(
                children: [
                  SizedBox(
                    height: rowHeight,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('服务开关',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        GFToggle(
                          onChanged: (bool? val) {
                            setState(() {
                              service = val!;
                            });
                          },
                          value: service,
                          type: GFToggleType.ios,
                          boxShape: BoxShape.circle,
                          enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                          enabledThumbColor: Colors.white,
                        )
                      ],
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: InkWell(
                      onTap: () {
                        // Get.toNamed(RouteGet.userStoreDeliveryPeriod);
                      },
                      child: Row(
                        children: [
                          Container(
                            width: leftWidth,
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '开启时段',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                            ),
                          ),
                          Expanded(
                              child: Container(
                            padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                            decoration: BoxDecoration(
                                color: ColorsUtils.rgba(247, 247, 247, 1),
                                borderRadius: BorderRadius.circular(Sizes.default10)),
                            alignment: Alignment.centerLeft,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text('同外卖营业时段',
                                    style:
                                        StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                                BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                              ],
                            ),
                          ))
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      children: [
                        Container(
                          width: leftWidth,
                          alignment: Alignment.centerLeft,
                          child: Text.rich(TextSpan(children: [
                            TextSpan(
                              text: '备货时间',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                            ),
                            TextSpan(
                                text: ' ✻',
                                style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color999, fontSize: Sizes.default12))
                          ])),
                        ),
                        Expanded(
                            child: Container(
                          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                          margin: const EdgeInsets.only(right: Sizes.default10),
                          decoration: BoxDecoration(
                              color: ColorsUtils.rgba(247, 247, 247, 1),
                              borderRadius: BorderRadius.circular(Sizes.default10)),
                          alignment: Alignment.centerLeft,
                          child: Text('30',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        )),
                        Container(
                          alignment: Alignment.centerRight,
                          child: Text('min',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        )
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: Sizes.default30,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('✻ 备货结束后顾客方能选择自取，限5-120分钟',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('优惠设置',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              padding:
                  const EdgeInsets.symmetric(vertical: Sizes.default8, horizontal: Sizes.default15),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: ListBody(
                children: [
                  SizedBox(
                    height: rowHeight,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('享受商品特价',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        GFToggle(
                          onChanged: (bool? val) {
                            setState(() {
                              special = val!;
                            });
                          },
                          value: special,
                          type: GFToggleType.ios,
                          boxShape: BoxShape.circle,
                          enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                          enabledThumbColor: Colors.white,
                        )
                      ],
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: InkWell(
                      onTap: () {
                        // Get.toNamed(RouteGet.userStoreDeliveryPeriod);
                      },
                      child: Row(
                        children: [
                          Container(
                            width: leftWidth,
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '参与自建活动',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                            ),
                          ),
                          Expanded(
                              child: Container(
                            padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                            decoration: BoxDecoration(
                                color: ColorsUtils.rgba(247, 247, 247, 1),
                                borderRadius: BorderRadius.circular(Sizes.default10)),
                            alignment: Alignment.centerLeft,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text('自动参与/5个参与/0个参与',
                                    style:
                                        StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                                BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                              ],
                            ),
                          ))
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  BrnCheckbox(
                    radioIndex: 0,
                    isSelected: agree,
                    iconPadding: const EdgeInsets.only(right: Sizes.default10),
                    onValueChangedAtIndex: (int index, bool value) {
                      setState(() {
                        agree = !agree;
                      });
                    },
                    childOnRight: true,
                    child: Text(
                      '我已阅读并同意签署',
                      style: StylesUtils.customTextStyle(
                          color: ColorsUtils.color999, fontSize: Sizes.default12),
                    ),
                  ),
                  TextButton(
                      onPressed: () {
                        Get.toNamed(RouteGet.userAboutProtocol);
                      },
                      child: Text(
                        '《到店自取服务协议》',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.colorFf6, fontSize: Sizes.default12),
                      ))
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: Sizes.default15),
              height: Sizes.default44,
              child: FractionallySizedBox(
                widthFactor: 0.9,
                child: GFButton(
                    onPressed: () {},
                    text: '确定',
                    textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16),
                    shape: GFButtonShape.pills,
                    type: GFButtonType.solid,
                    size: GFSize.LARGE,
                    color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
              ),
            )
          ],
        ),
      ),
    );
  }
}
